<?php
/**
 * Description of mysql
 *
 * @author Андрей
 */
class Generator_Mysql extends Generator
{
    public function parse_type($type) 
    {
        $type = str_replace('string', 'varchar', $type);
	$type = str_replace('uniq', '', $type);
        $type = str_replace('many', '', $type);
        $type = str_replace('one', '', $type);
        return trim($type);
    }

    public function parse_field($line, $separator=':')
    {
        $kv = explode($separator, $line);
        $is_ref = (strpos($kv[1], 'ref') !== FALSE);
        $ref_type = (preg_match('(one|many)', $kv[1], $regs) ? $regs[0]:'');

        return array(
            'name' => trim($is_ref ? $kv[0].'_id':$kv[0]),
            'type' => trim($is_ref ? 'int UNSIGNED' : $this->parse_type($kv[1])),
            'ref' => trim($is_ref ? $kv[0]:''),
            'ref_type' => $ref_type,
            'uniq' => (strpos($kv[1], 'uniq') !== FALSE),
            'null' => (strpos($kv[1], 'null') !== FALSE),
        );
    }
}
?>
